cmake_minimum_required(VERSION 3.15)

project(template LANGUAGES CXX)

# ![Enable automatic processing of Qt moc/uic/rcc preprocessor]
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# ![build QScintilla]
##########################################################
# scintilla sources files
file(GLOB _file_glob_scintilla
    libs/QScintilla_src-2.14.1/scintilla/include/*.h
    libs/QScintilla_src-2.14.1/scintilla/lexers/*.cpp
    libs/QScintilla_src-2.14.1/scintilla/lexlib/*.h
    libs/QScintilla_src-2.14.1/scintilla/lexlib/*.cpp
    libs/QScintilla_src-2.14.1/scintilla/src/*.h
    libs/QScintilla_src-2.14.1/scintilla/src/*.cpp)

# Qsci/QsciScintilla sources files
file(GLOB _file_glob_qsciscintilla 
    libs/QScintilla_src-2.14.1/src/Qsci/*.h
    libs/QScintilla_src-2.14.1/src/*.h 
    libs/QScintilla_src-2.14.1/src/*.cpp)

set(_file_glob_sources)
foreach(item IN LISTS _file_glob_qsciscintilla _file_glob_scintilla)
    # string(FIND "${item}" "qsciprinter.h"   has_header REVERSE)
    # string(FIND "${item}" "qsciprinter.cpp" has_source REVERSE)
    # if(NOT has_header EQUAL -1)
    #     continue()
    # endif(NOT has_header EQUAL -1)
    # if(NOT has_source EQUAL -1)
    #     continue()
    # endif(NOT has_source EQUAL -1)
    list(APPEND _file_glob_sources "${item}")
endforeach()

##########################################################
# build as a shared/static library
add_library(QScintilla STATIC #SHARED
    ${_file_glob_sources}
)
##########################################################
# include path of all header files.
target_include_directories(QScintilla PUBLIC 
    libs/QScintilla_src-2.14.1/scintilla/include
    libs/QScintilla_src-2.14.1/scintilla/lexlib
    libs/QScintilla_src-2.14.1/scintilla/src
    libs/QScintilla_src-2.14.1/scintilla

    libs/QScintilla_src-2.14.1/src)

##########################################################
# features: look libs/README.md or libs/QScintilla_src-2.14.1/src/qscintilla.pro
target_compile_definitions(QScintilla 
    PUBLIC 
        SCINTILLA_QT                # 
        SCI_LEXER                   # 
        INCLUDE_DEPRECATED_FEATURES # 
)

##########################################################
# based Qt5 library
find_package(Qt5 COMPONENTS Core Widgets Gui Concurrent PrintSupport REQUIRED)
# target_include_directories(QScintilla PUBLIC Qt5::Core Qt5::Widgets Qt5::Gui)
target_link_libraries(QScintilla PUBLIC Qt5::Core Qt5::Widgets Qt5::Gui Qt5::Concurrent Qt5::PrintSupport)


# ![build QScintilla]

option(MAKE_PROJECT "Take this project as an executable project." OFF)
if(MAKE_PROJECT)
    add_executable(main src/main.cpp)
    target_link_libraries(main QScintilla)
    target_include_directories(main PRIVATE libs/QScintilla_src-2.14.1/src)
endif(MAKE_PROJECT)
